package cn.terminus.biz.customer.contractsellclauseinfo;

import cn.terminus.biz.customer.common.AbstractTerminusManager;
import cn.terminus.common.customer.bean.contractsellclauseinfo.dto.*;
import cn.terminus.data.customer.contractsellclauseinfo.dao.ContractSellClauseInfoDao;
import cn.terminus.result.common.exception.DataAccessException;
import cn.terminus.result.common.page.TerminusPageAble;
import cn.terminus.result.common.page.TerminusPageInfo;
import cn.terminus.result.common.util.BeanCopyUtils;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 合同售卖条款信息(ContractSellClauseInfo)表服务实现类
 *
 * @author makejava
 * @since 2021-07-21 11:17:36
 */
@Component
public class ContractSellClauseInfoManager extends AbstractTerminusManager {
    @Autowired
    private ContractSellClauseInfoDao contractSellClauseInfoDao;

    public Integer add(ContractSellClauseInfoNewDto dto) throws DataAccessException {
        try {
            return contractSellClauseInfoDao.add(dto);
        } catch (Exception e) {
            logger.error("ContractSellClauseInfoManager新增失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public Integer update(ContractSellClauseInfoEditDto dto) throws DataAccessException {
        try {
            return contractSellClauseInfoDao.update(dto);
        } catch (Exception e) {
            logger.error("ContractSellClauseInfoManager更新失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public List<ContractSellClauseInfoResultDto> gets(ContractSellClauseInfoGetsDto dto) throws DataAccessException {
        try {
            return contractSellClauseInfoDao.gets(dto);
        } catch (Exception e) {
            logger.error("ContractSellClauseInfoManager查询失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public List<ContractSellClauseInfoResultDto> query(ContractSellClauseInfoQueryDto dto) throws DataAccessException {
        try {
            return contractSellClauseInfoDao.query(dto);
        } catch (Exception e) {
            logger.error("ContractSellClauseInfoManager查询失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public Integer delete(ContractSellClauseInfoDeleteDto dto) throws DataAccessException {
        try {
            return contractSellClauseInfoDao.delete(dto);
        } catch (Exception e) {
            logger.error("ContractSellClauseInfoManager删除失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public TerminusPageAble<ContractSellClauseInfoResultDto> page(ContractSellClauseInfoQueryDto dto, TerminusPageInfo page) throws DataAccessException {
        try {
            PageHelper.startPage(page.getCurrentPage(), page.getPageSize());
            Page<ContractSellClauseInfoResultDto> result = (Page<ContractSellClauseInfoResultDto>) contractSellClauseInfoDao.query(dto);
            return new TerminusPageAble<>(BeanCopyUtils.copy(result.getResult(), ContractSellClauseInfoResultDto.class), page, result.getTotal());
        } catch (Exception e) {
            logger.error("ContractSellClauseInfoManager分页查询失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public Integer deleteWithContractId(Long id) throws DataAccessException {
        try {
            return contractSellClauseInfoDao.deleteWithContractId(id);
        } catch (Exception e) {
            logger.error("deleteWithContractId删除失败，原因：", e);
            throw new DataAccessException(e);
        }
    }
}
